home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GamePlayer.as < prev    next >
Encoding:
Text File  |  2006-11-29  |  1.9 KB  |  98 lines

  1. class GamePlayer
  2. {
  3.    var control;
  4.    var lastKey;
  5.    var score = 0;
  6.    var health = 1;
  7.    var lives = 3;
  8.    var shield = 0;
  9.    var fuel = 0;
  10.    var left = false;
  11.    var right = false;
  12.    var up = false;
  13.    var down = false;
  14.    var jump = false;
  15.    var action = false;
  16.    function GamePlayer()
  17.    {
  18.       this.initialize();
  19.       this.lives = !_global.VR_ON_LIVES ? 3 : 5;
  20.    }
  21.    function initialize()
  22.    {
  23.       Key.addListener(this);
  24.    }
  25.    function destroy()
  26.    {
  27.       Key.removeListener(this);
  28.    }
  29.    function setControl(obj)
  30.    {
  31.       this.control.deactivate();
  32.       this.control.active = false;
  33.       this.control = obj;
  34.       obj.controller = this;
  35.       obj.active = true;
  36.       obj.activate();
  37.    }
  38.    function shiftScore(value)
  39.    {
  40.       this.score += value;
  41.    }
  42.    function update(elapsed)
  43.    {
  44.       this.control.update(elapsed);
  45.       this.clearKeys();
  46.    }
  47.    function onKeyDown()
  48.    {
  49.       if(this.lastKey == (this.lastKey = Key.getCode()))
  50.       {
  51.          return undefined;
  52.       }
  53.       switch(this.lastKey)
  54.       {
  55.          case 37:
  56.             this.left = true;
  57.             break;
  58.          case 38:
  59.             this.up = true;
  60.             break;
  61.          case 39:
  62.             this.right = true;
  63.             break;
  64.          case 40:
  65.             this.down = true;
  66.             break;
  67.          case 32:
  68.             this.jump = true;
  69.             break;
  70.          case 68:
  71.             this.action = true;
  72.       }
  73.    }
  74.    function onKeyUp()
  75.    {
  76.       switch(Key.getCode())
  77.       {
  78.          case 37:
  79.             this.left = false;
  80.             break;
  81.          case 38:
  82.             this.up = false;
  83.             break;
  84.          case 39:
  85.             this.right = false;
  86.             break;
  87.          case 40:
  88.             this.down = false;
  89.       }
  90.       this.lastKey = 0;
  91.    }
  92.    function clearKeys()
  93.    {
  94.       this.jump = false;
  95.       this.action = false;
  96.    }
  97. }
  98.